<?php

/* @var $this yii\web\View */

use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\helpers\Render;
use common\models\Article;

$this->addCrumbs('文章列表', 'article/article-list');
$this->title = (isset($data['id']) ? '修改' : '添加'). '文章';
?>

<form class="box-content flyer-form pane gap" id="flyer-create" flyer="tabs" action="<?= Url::to('@web/article/article-'.(isset($data['id']) ? 'update?id='.$data['id'] : 'insert')) ?>" method="post">
    <div class="flyer-tabs gap" flyer="tabs">
        <div class="tab-header">
            <span class="header active"><i class="icon-gear"></i> 配置信息<i class="notice icon-info-circle"></i></span>
            <span class="header"><i class="icon-list-alt"></i> 文章信息<i class="notice icon-info-circle"></i></span>
        </div>
        <div class="tab-contenter flyer-form pane">
            <div class="contenter active">
                <div class="form-item checker">
                    <div class="input-title">标题</div>
                    <div class="input-block"><input class="flyer-input" type="text" name="title" value="<?= Render::value($data, 'title') ?>" placeholder="title."></div>
                </div>
                <div class="form-item">
                    <div class="item-inline checker">
                        <div class="input-title">分类</div>
                        <div class="input-inline"><?= Render::select('category_id[]', [], null, ['flyer' => 'select', 'id' => 'category', 'data-select' => Render::value($data, 'category_id')]) ?></div>
                    </div>
                </div>
                <div class="form-item">
                    <div class="item-inline checker">
                        <div class="input-title">作者</div>
                        <div class="input-inline"><input class="flyer-input" type="text" name="author" value="<?= Render::value($data, 'author') ?>" placeholder="author."></div>
                    </div>
                    <div class="item-inline checker">
                        <div class="input-title">来源</div>
                        <div class="input-inline"><input class="flyer-input" type="text" name="come" value="<?= Render::value($data, 'come', '原创') ?>" placeholder="come."></div>
                    </div>
                </div>
                <div class="form-item item-text">
                    <div class="input-title">推荐类型</div>
                    <div class="input-block">
                        <div class="auto flyer-choise-conter checker">
                            <?php foreach(Article::$typeSelector as $id => $title) { ?>
                                <input flyer="checkbox" type="checkbox" name="types[]" value="<?= $id ?>" title="<?= $title['title'] ?>"<?= isset($data['id']) && ($id & $data['types']) ? ' checked' : '' ?>>
                            <?php } ?>
                        </div>
                    </div>
                </div>
                <div class="form-item checker">
                    <div id="uploader"></div>
                    <input id="image-input" name="image" type="text" value="<?= Render::value($data, 'image') ?>" style="display:none;">
                </div>
                <div class="form-item checker">
                    <div class="input-title">标签</div>
                    <div class="input-block"><input class="flyer-input" type="text" name="tags" value="<?= Render::value($data, 'tags') ?>" placeholder="标签，以半角‘;’分割，每个不能超过4个字."></div>
                </div>
            </div>
            <div class="contenter mb-10px">
                <div class="form-item item-text checker">
                    <!--div class="input-title">文章内容</div-->
                    <div class="input-block bdn"><textarea id="content" name="content" placeholder="详细内容."><?= Render::value($data, 'content') ?></textarea></div>
                </div>
            </div>
        </div>
    </div>
    <div class="form-item mt-10px">
        <div class="input-block tr bdn"><button class="flyer-button normal border-round" id="save-button" type="submit"><i class="icon-save"></i> 保 存</button></div>
        <textarea id="flyer-create-json" data-form="#flyer-create" style="display:none;"><?= Article::checker(isset($data['id']) ? 'update' : 'insert') ?></textarea>
    </div>
    <input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken() ?>">
</form>

<script src="<?= Render::static('flyer/flyer.class.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('system/category-article.data.js') ?>"></script>
<script src="<?= Render::static('flyer/categorier.class.js') ?>"></script>
<!-- 百度编辑器功能插件引入 -->
<script src="<?= Render::static('ueditor.1.4.3/ueditor.config.mini.js') ?>"></script>
<script src="<?= Render::static('ueditor.1.4.3/ueditor.all.min.js') ?>"></script>
<!-- 图片批量上传功能插件引入 -->
<link href="<?= Render::static('uploader/loader.css') ?>" rel="stylesheet">
<script src="<?= Render::static('uploader/loader.core.single.class.js') ?>"></script>
<script src="<?= Render::static('uploader/loader.image.class.js') ?>"></script>
<script>
    $(document).ready(function() {
        // 初始化Category
        (new categorier()).init({ fix: false, dom: '#category', data: ArticleCategories, relate: ArticleCategoriesRelation, start: '<?= Yii::$app->params['articleCategories'] ?>' });
        // Form 元素初始化
        (new flyer).init({ form: '#flyer-create' });
        // 表单数据验证
        (new checker).init({ ruleDom: '#flyer-create-json' });
        // 内容输入框初始化
        var ueditor = UE.getEditor('content', {initialFrameHeight: 500, initialFrameWidth: 'auto'});
        // 初始化 图片上传插件
        (new loaderImage()).init({
            conter: '#uploader',
            prevLoaders: "<?= isset($data['id']) ? Render::upload(Render::value($data, 'image')) : '' ?>",
            action: '<?= Url::to('@web/article/article-uploader') ?>',
            onSuccess: function (file, response) {
                response = $.parseJSON(response);
                $('#image-input').val(response.path);
            },
            onFailure: function (file) {
                layer.alert('图片 ' + file.name + ' 上传失败！', {icon: 2});
            }
        });
    });
</script>